package com.lsmgc.cms.service.classify;

import com.lsmgc.cms.constant.SysConstant;
import com.lsmgc.cms.dao.classify.ClassifyDao;
import com.lsmgc.cms.entity.classify.Classify;
import com.lsmgc.cms.entity.classify.ClassifyQuery;
import com.lsmgc.cms.util.page.Pagination;
import org.apache.commons.lang3.StringUtils;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ClassifyService {
    private ClassifyDao classifyDao = new ClassifyDao();

    public boolean addClassify(Classify classify) throws SQLException {
        int n = classifyDao.addClassify(classify);
        if (n > 0) {
            return true;
        }
        return false;
    }

    public Pagination getClassifyList(ClassifyQuery classifyQuery) throws SQLException {
        Pagination pagination = new Pagination(classifyQuery.getPageNo(), classifyQuery.getPageSize(),classifyDao.getClassifyListPageCount(classifyQuery).intValue());
        List<Classify> list = classifyDao.getClassifyListPage(classifyQuery);
        if (list==null) {
            list = new ArrayList<>();
        }
        pagination.setList(list);
        return pagination;
    }

    public Classify getClassifyById(Long id) throws SQLException {
        return classifyDao.getClassifyById(id);
    }

    public boolean updateClassifyById(Classify classify) throws SQLException {
        int n = classifyDao.updateClassifyById(classify);
        if (n > 0) {
            return true;
        }
        return false;
    }

    public boolean deleteClassifyById(Long id) throws SQLException {
        int n = classifyDao.deleteClassifyById(id);
        if (n > 0) {
            return true;
        }
        return false;
    }
}
